﻿<%@ Page Language="VB" inherits="Boogaloo.Core.UI.BaseAdminPage" 
MasterPageFile="~/Admin/Masters/Base.master" title="Mindfly Web Studio's Boogaloo - Dashboard" maintainscrollpositiononpostback="true" %>
<%@import namespace="Boogaloo.Core.BLL" %>
<%@import namespace="Boogaloo.Core.UI" %>
<%@ register tagprefix="mfb" tagname="hostNav" src="~/Admin/Controls/Host_navigation.ascx" %>
<%@ register tagprefix="mfb" tagname="iconnavigation" src="~/Admin/Controls/Admin_IconNavigation.ascx" %>
<%@ register tagprefix="mfb" tagname="comments" src="~/Admin/Controls/Dash_Comments.ascx" %>
<%@ register tagprefix="mfb" tagname="publishmanager" src="~/Admin/Controls/Dash_PublishManager.ascx" %>
<script runat="server">    
    ' Boogaloo® - http://www.mindfly.com
    ' Copyright (c) 2008
    ' by Mindfly, Inc.
    '   
    ' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
    ' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
    ' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
    ' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
    ' of the Software.
    '
    ' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    ' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    ' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    ' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    ' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    ' WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    ' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        
        hyp_members.NavigateUrl = String.Format("{0}/Users.aspx", Groove.path_admin_membership)
        
        If Groove.admin_root.default_node IsNot Nothing Then
            hyp_designer.NavigateUrl = String.Format("{0}Designer.aspx?node={1}", Groove.path_admin_site, Groove.admin_root.default_node.node_id)
            
            If Not Groove.admin_root.HasNodesManagedByPublish Then
                div_publish.Visible = False
            End If
            
        Else
            div_pages.Visible = False
            div_publish.Visible = False
        End If
        
        
        ' members
        Dim member_count As Integer = Membership.GetAllUsers().Count
        Dim online_count As Integer = Membership.GetNumberOfUsersOnline
        Dim is_are As String = IIf(member_count = 1, "is", "are")
        Dim plural As String = IIf(member_count = 1, "", "s")
        Dim member_text As String = String.Format("There {0} {1} user{2} registered", is_are, member_count.ToString, plural)
        is_are = IIf(online_count = 1, "is", "are")
        member_text &= String.Format(" and {0} of them {1} online", online_count.ToString, is_are)
        lit_membertext.Text = member_text
        
        
        ' Extensions
            
        If Groove.extensions.Count > 0 Then
                
            rpt_extensions.DataSource = Groove.extensions
            rpt_extensions.DataBind()
        Else
            rpt_extensions.Visible = False
        End If
        
        
        If Not Page.IsPostBack Then
            
            rpt_recent_pages.DataSource = Groove.admin_root.GetMostRecentNodes(3)
            rpt_recent_pages.DataBind()
            If rpt_recent_pages.Items.Count = 0 Then rpt_recent_pages.Visible = False
            
            Dim prof As ProfileCommon = Profile.GetProfile(Membership.GetUser().UserName)
            Dim favs As String() = prof.Boogaloo.FavoritePages.Split(",")
            Dim fav_nodes As New List(Of Node)
            Dim id As String = String.Empty
            For Each id In favs
                Dim n As Node = Nothing
                Try
                    n = Node.GetNode(CType(id.Trim, Integer))                    
                Catch ex As Exception
                    n = Nothing
                End Try
                If n IsNot Nothing Then fav_nodes.Add(n)
            Next
                
            rpt_favorite_pages.DataSource = fav_nodes
            rpt_favorite_pages.DataBind()
            If rpt_favorite_pages.Items.Count = 0 Then rpt_favorite_pages.Visible = False
            
            
            
        End If
    End Sub
    
    
    Protected Sub rpt_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) _
        Handles rpt_recent_pages.ItemDataBound, rpt_favorite_pages.ItemDataBound
        
        Dim n As Node = CType(e.Item.DataItem, Node)
        If n IsNot Nothing Then
            Dim hyp As HyperLink = CType(e.Item.FindControl("hyp"), HyperLink)
            hyp.NavigateUrl = String.Format("{0}/Designer.aspx?node={1}", Groove.path_admin_site, n.node_id.ToString)
            hyp.Text = n.menu_item_text
            
            Dim lbl As Label = CType(e.Item.FindControl("lbl"), Label)
            If lbl IsNot Nothing Then lbl.Text = n.last_modified_date.ToShortDateString
            
            
        End If
        
    End Sub
    
    Protected Sub rpt_extensions_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rpt_extensions.ItemDataBound
        Dim c As Component = CType(e.Item.DataItem, Component)
        If c IsNot Nothing Then
            
            
            Dim hyp As HyperLink = CType(e.Item.FindControl("hyp"), HyperLink)
            Dim ph As PlaceHolder = CType(e.Item.FindControl("ph"), PlaceHolder)

            If Not String.IsNullOrEmpty(c.panel_ascx) Then
                hyp.Visible = False
                Dim path As String = c.panel_ascx
                If path.Contains("{0}") Then
                    path = String.Format(path, Groove.path_admin)
                End If
                Try
                    ph.Controls.Add(Me.LoadControl(path))
                Catch ex As Exception
                    ph.Controls.Add(New LiteralControl(ex.Message))
                End Try
                
                
            Else
                
                hyp.NavigateUrl = c.admin_virtual_path
                If Not String.IsNullOrEmpty(c.menu_text) Then
                    hyp.Text = c.menu_text
                Else
                    hyp.Text = c.name
                End If
            End If
            

        End If
    End Sub
    
</script>


<asp:content contentplaceholderid="MainContent" id="MainContent" runat="server">
    
    <mfb:hostnav id="ctlHostNav" runat="server" />
    
    <div id="div_pages" class="dashboardCategory pages" runat="server">
    <h3 class="box enriched"><asp:hyperlink id="hyp_designer" runat="server" text="Pages" /></h3>
        <h4>Recent Pages</h4>
        <asp:repeater id="rpt_recent_pages" runat="server">
        <headertemplate><ul></headertemplate>
        <itemtemplate><li><asp:hyperlink id="hyp" runat="server" /> <asp:label id="lbl" runat="server" /></li></itemtemplate>
        <footertemplate></ul></footertemplate>
        </asp:repeater>
               
        <asp:repeater id="rpt_favorite_pages" runat="server">
        <headertemplate>
        <h4>Favorite Pages</h4>
        <ul></headertemplate>
        <itemtemplate><li><asp:hyperlink id="hyp" runat="server" /></li></itemtemplate>
        <footertemplate></ul></footertemplate>
        </asp:repeater>
        
    </div>

    
    <div id="div_publish" class="dashboardCategory" runat="server">
    <h3 class="box enriched">Publish</h3>
    <mfb:publishmanager runat="server" />
    </div>
    
    <div id="div_members" class="dashboardCategory members" runat="server">
    <h3 class="box enriched"><asp:hyperlink id="hyp_members" runat="server" text="Members" /></h3>
    <asp:literal id="lit_membertext" runat="server" />
    </div>
    
    
    <div id="div_extensions" class="dashboardCategory extensions" runat="server">
    <h3 class="box enriched">Extensions</h3>
    <asp:repeater id="rpt_extensions" runat="server">
    <headertemplate><ul id="extensionList"></headertemplate>
    <itemtemplate><li><asp:hyperlink id="hyp" runat="server" /><asp:placeholder id="ph" runat="server" /></li>
    </itemtemplate>
    <footertemplate></ul></footertemplate>
    </asp:repeater>
    </div>


    <div id="div_comments" class="dashboardCategory" runat="server">
    <h3 class="box enriched">Comments</h3>
    <mfb:comments runat="server" />
    
    </div>

</asp:content>

<asp:content id="SubContent" contentplaceholderid="SubContent" runat="server">
    <mfb:iconnavigation runat="server" />    
    
</asp:content>